package com.aj.controller;

import com.aj.Interface.OrderSettingListService;
import com.aj.common.MessageConstant;
import com.alibaba.dubbo.config.annotation.Reference;
import entity.PageResult;
import entity.QueryPageBean;
import entity.Result;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RequestMapping("/ordersettinglist")
@RestController
public class OrderSettingListController {
    @Reference
    OrderSettingListService orderSettingListService;
    @RequestMapping("/findpage")
    public PageResult findPage(@RequestBody QueryPageBean queryPageBean){
        System.out.println(queryPageBean);
      try{
          PageResult page = orderSettingListService.findPage(queryPageBean);
        System.out.println(page);
      return page;
      }catch (Exception e){
          return null;
      }

    }


    @RequestMapping("/add")
    public Result add(@RequestBody Map map,Integer[] checkitemIds){
        System.out.println(map+" "+checkitemIds);
      try {
          orderSettingListService.add(map,checkitemIds);
          return new Result(true,MessageConstant.ADD_ORDERBOOK_SUCCESS);
      }catch (Exception e){
          e.printStackTrace();
          return new Result(false,MessageConstant.ADD_ORDERBOOK_FAIL);

      }
    }
    @RequestMapping("/update")
    public Result update(@RequestBody Map map,Integer[] checkitemIds){
        try {
            System.out.println(map);
            for (Integer i:checkitemIds){
                System.out.println(i);
            }
            orderSettingListService.update(map,checkitemIds);
            return new Result(true,MessageConstant.EDIT_ORDERMESSAGE_SUCCESS);

        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,MessageConstant.EDIT_ORDERMESSAGE_FAIL);

        }
    }

    @RequestMapping("/delete")
    public Result delete(int id){
       try{ orderSettingListService.delete(id);
       return new Result(true,MessageConstant.DELETE_ORDERMESSAGE_SUCCESS);
       }catch (Exception e){
           return new Result(false,MessageConstant.DELETE_ORDERMESSAGE_FAIL);

       }

    }
    @RequestMapping("/getSetmealIdByMemberId")
    public List getSetmealId( int id){
        System.out.println(id+"!!!!!!!!!!!!");
        List setmealId = orderSettingListService.findSetmealId(id);
        System.out.println(setmealId);
        return setmealId;

    }
}
